package top.hzy520.common.listener;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.springframework.transaction.annotation.Transactional;
import top.hzy520.common.constants.Constants;
import top.hzy520.common.factory.SpringBeanFactoryUtils;
import top.hzy520.online.dao.OnlineUserMapper;
import top.hzy520.online.entity.OnlineUser;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 15:25 2018/9/27
 */
public class HttpSessionListener implements SessionListener {


    @Override
    public void onStart(Session session) {

    }

    @Override
    public void onStop(Session session) {

    }

    @Override
    @Transactional
    public void onExpiration(Session session) {
        OnlineUserMapper onlineUserMapper= SpringBeanFactoryUtils.getBean(OnlineUserMapper.class);
     OnlineUser onlineUser=onlineUserMapper.selectUserBySessionId(String.valueOf(session.getId()));
     onlineUser.setSessionStatus(Constants.REQUEST_SESSION_STATUS_UNONLINE);
     onlineUserMapper.updateByPrimaryKeySelective(onlineUser);
    }
}
